#!/bin/sh
# - interval

file=$(basename $0)
file=${file#proc-}

get_sysfs_path()
{
	local sysfs_path
	if [ $file = 'sched_debug' ]; then
		sysfs_path="/sys/kernel/debug/sched/debug"
		[ -f $sysfs_path ] || sysfs_path="/proc/sched_debug"
	else
		sysfs_path="/proc/$file"
	fi

	[ -f $sysfs_path ] || return

	echo "$sysfs_path"
}

syspath=$(get_sysfs_path) || exit
test -r $syspath || {
	echo "$0: quit gracefully due to no read permission to $syspath" >&2
	exit 0
}

if [ -z "$interval" ]; then
	case $file in
		sched_debug)	interval=60 ;;
		stat)		interval=10 ;;
		zoneinfo)	interval=10 ;;
		*)		interval=1  ;;
	esac
fi

. $LKP_SRC/lib/wait.sh
setup_wait

if [ $file = 'vmstat' ]; then
	cat()
	{
		awk '!x[$1]++' "$@"
	}
fi

while :
do
	echo time: $(date +%s)
	cat $syspath
	wait_timeout $interval
done
